'use strict';
var m = Object.defineProperty;
var S = (s, i, e) =>
  i in s
    ? m(s, i, { enumerable: !0, configurable: !0, writable: !0, value: e })
    : (s[i] = e);
var c = (s, i, e) => (S(s, typeof i != 'symbol' ? i + '' : i, e), e);
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const h = require('../doc/createNode.cjs'),
  g = require('../stringify/stringifyCollection.cjs'),
  p = require('./Collection.cjs'),
  u = require('./identity.cjs'),
  y = require('./Scalar.cjs'),
  q = require('./toJS.cjs');
class b extends p.Collection {
  constructor(e) {
    super(u.SEQ, e);
    c(this, 'items', []);
  }
  static get tagName() {
    return 'tag:yaml.org,2002:seq';
  }
  add(e) {
    this.items.push(e);
  }
  delete(e) {
    const t = a(e);
    return typeof t != 'number' ? !1 : this.items.splice(t, 1).length > 0;
  }
  get(e, t) {
    const r = a(e);
    if (typeof r != 'number') return;
    const n = this.items[r];
    return !t && u.isScalar(n) ? n.value : n;
  }
  has(e) {
    const t = a(e);
    return typeof t == 'number' && t < this.items.length;
  }
  set(e, t) {
    const r = a(e);
    if (typeof r != 'number')
      throw new Error(`Expected a valid index, not ${e}.`);
    const n = this.items[r];
    u.isScalar(n) && y.isScalarValue(t) ? (n.value = t) : (this.items[r] = t);
  }
  toJSON(e, t) {
    const r = [];
    t != null && t.onCreate && t.onCreate(r);
    let n = 0;
    for (const o of this.items) r.push(q.toJS(o, String(n++), t));
    return r;
  }
  toString(e, t, r) {
    return e
      ? g.stringifyCollection(this, e, {
          blockItemPrefix: '- ',
          flowChars: { start: '[', end: ']' },
          itemIndent: (e.indent || '') + '  ',
          onChompKeep: r,
          onComment: t,
        })
      : JSON.stringify(this);
  }
  static from(e, t, r) {
    const { replacer: n } = r,
      o = new this(e);
    if (t && Symbol.iterator in Object(t)) {
      let f = 0;
      for (let l of t) {
        if (typeof n == 'function') {
          const d = t instanceof Set ? l : String(f++);
          l = n.call(t, d, l);
        }
        o.items.push(h.createNode(l, void 0, r));
      }
    }
    return o;
  }
}
function a(s) {
  let i = u.isScalar(s) ? s.value : s;
  return (
    i && typeof i == 'string' && (i = Number(i)),
    typeof i == 'number' && Number.isInteger(i) && i >= 0 ? i : null
  );
}
exports.YAMLSeq = b;
